<template>
  <div class="app-container">
    <nabtwo index="1" :params="param" ></nabtwo>
    <topIndex style="margin-bottom: 20px;" :indexCount="indexCount"></topIndex>
    <el-form :model="queryParams" class="frominfo" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <div class="from-item">
        <el-form-item label="群名称" prop="wcGroupName">
          <el-input v-model="queryParams.wcGroupName" @keyup.enter.native="handleQuery" placeholder="请输入群名称" clearable/>
        </el-form-item>
        <el-form-item label="群备注" prop="wcGroupNoteName">
          <el-input v-model="queryParams.wcGroupNoteName" @keyup.enter.native="handleQuery" placeholder="请输入群备注" clearable/>
        </el-form-item>
        <el-form-item label="聊天时间" prop="lastChatTime">
          <el-date-picker v-model="chatTime" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
        </el-form-item>
        <!-- <el-form-item label="好友占比" prop="groupFirendsScale">
          <el-select v-model="range" placeholder="请选择群好友占比" clearable>
            <el-option v-for="dict in dict.type.sys_friend_proport" :key="dict.value" :label="dict.label" :value="dict.value"/>
          </el-select>
        </el-form-item> -->
      </div>
      <div class="from-Btn">
        <el-form-item>
            <el-button class="blue-button" type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </div>
    </el-form>

    <el-table v-loading="loading" :data="wcGroupsInfoList" :header-cell-style="{ background: '#fcfcfd', color: '#000' }" :border="false">
      <el-table-column label="群名称" prop="wcGroupName" align="center" :show-overflow-tooltip="true"/>
      <el-table-column label="最近聊天时间" prop="lastChatTime" align="center" :show-overflow-tooltip="true" width="180">
            <template slot-scope="scope">
                <span>{{ parseTime(scope.row.lastChatTime, '{y}-{m}-{d} {h}:{i}') }}</span>
            </template>
      </el-table-column>
      <el-table-column label="群备注" prop="wcGroupNoteName" align="center" :show-overflow-tooltip="true"/>
      <el-table-column label="群好友占比" prop="groupFirendsNum" align="center" :show-overflow-tooltip="true">
          <template slot-scope="scope" v-if="scope.row.groupFirendsNum!=null">
            <span>{{scope.row.groupFirendsNum}}人</span>
          </template>
      </el-table-column>
      <!-- <el-table-column label="群好友占比" prop="groupFirendsScale" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope" v-if="scope.row.groupFirendsScale!=null">
          <span>{{scope.row.groupFirendsScale}}%</span>
        </template>
      </el-table-column> -->
      <el-table-column align="center" width="120" class-name="small-padding fixed-width">
        <template slot="header">
          <span>群详情</span>
          <el-tooltip class="item" effect="dark" content="进入操作" placement="top">
            <i class="el-icon-warning" style="color:#8c8c8c;"></i>
          </el-tooltip>
        </template>
        <template slot-scope="scope">
           <span style="cursor: pointer;color:#0078fb" @click="golink(scope.row.wcGroupId,scope.row.wcId,scope.row.wcName)">详情</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList"/>

  </div>
</template>

<script>
import request from '@/utils/request'
import mathNum from "../../components/daily.js"
import topIndex from '../../components/top-index.vue'
import nabtwo from '../../components/nabtwo.vue'
import { checkPermi } from "@/utils/permission"; // 权限判断函数
export default {
  name: "WcGroupsInfo",
  dicts: ['sys_friend_proport'],
  components:{
    nabtwo,
    topIndex,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 微信群信息表格数据
      wcGroupsInfoList: [],
      // 是否显示弹出层
      open: false,
      param:{wxid:this.$route.query.wxid,userid:this.$route.query.userid},
      chatTime:[],
      range:null,
      rangeArr:[[0,25],[25,50],[50,75],[75,100]],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        wcId: null,
        assistId: null,
        wcGroupName: null,
        wcGroupNoteName: null,
        beginTime: null,
        endTime: null,
        begin:null,
        end:null,
      },
      indexCount:[{name:'今日新加群',num:0,type:1,bili:0},{name:'今日新加群内好友',num:0,type:0,bili:0},{name:'今日群内发言',num:0,type:0,bili:0}],
    };
  },
  created() {
    
  },
  mounted(){
    this.queryParams.wcId = this.$route.query.wxid;
    this.getList();
    getNewGroupNum({wcId:this.$route.query.wxid}).then(res => {
      //console.log(res)
      if(res.code==200){
        if(res.data){
          this.indexCount[0].type=mathNum(res.data.new_size,res.data.old_size).split('_')[0]
          this.indexCount[0].bili=mathNum(res.data.new_size,res.data.old_size).split('_')[1]
          this.indexCount[0].num=res.data.new_size
        }
      }
    })
    getGroupsFriend({wcId:this.$route.query.wxid}).then(res => {
      //console.log(res)
      if(res.code==200){
        if(res.data){
          this.indexCount[1].type=mathNum(res.data.new_size,res.data.old_size).split('_')[0]
          this.indexCount[1].bili=mathNum(res.data.new_size,res.data.old_size).split('_')[1]
          this.indexCount[1].num=res.data.new_size
        }
      }
    })
    getGroupSpeak({wcId:this.$route.query.wxid}).then(res => {
      //console.log(res)
      if(res.code==200){
        if(res.data){
            this.indexCount[2].type=mathNum(res.data.new_size,res.data.old_size).split('_')[0]
            this.indexCount[2].bili=mathNum(res.data.new_size,res.data.old_size).split('_')[1]
            this.indexCount[2].num=res.data.new_size
        }
      }
    })
  },
  methods: {
    checkPermi,
    golink(groupid,wxid,name){
      if(this.checkPermi(['massage:massage:getMags'])){
        this.$router.push({ path:"/group/detial/",name:'detial',query: { groupid,wxid,name}}).catch(()=>{});
      }else{
        this.$router.push({ path:"/group/notadd/",name:'notadd',query: {wxid,groupid,name}}).catch(()=>{});
      }
    },
    /** 查询微信群信息列表 */
    getList() {
      this.loading = true;
      listWcGroupsInfo(this.queryParams).then(res => {
        //console.log(res)
        if (res['success']) {
          const dt = res['data'];
          this.total = dt['map'].total;
          this.wcGroupsInfoList = dt['wcGrpupsinfoVsitList'];
          // this.wcGroupsInfoList = dt['records'];
        }
        this.loading = false;
      });
      setTimeout(()=>{
        this.loading = false;
      },2000)
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.beginTime=null
      this.queryParams.endTime=null
      this.queryParams.begin=null
      this.queryParams.end=null
      if(this.chatTime!=''&&this.chatTime!=null){
        this.queryParams.beginTime=this.chatTime[0]+' 00:00:00'
        this.queryParams.endTime=this.chatTime[1]+' 23:59:59'
      }
      if(this.range!=''&&this.range!=null){
        this.queryParams.begin=this.rangeArr[this.range][0]+' 00:00:00'
        this.queryParams.end=this.rangeArr[this.range][1]+' 23:59:59'
      }
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.chatTime=[]
      this.range=null
      this.handleQuery();
    },
  }
};

/** js请求 调用 */

// 查询微信群信息列表
export function listWcGroupsInfo(query) {
  return request({
    url: '/arbit/wcgroups_info/page',
    method: 'get',
    params: query
  })
}

// 查询微信群信息详细
export function getWcGroupsInfo(id) {
  return request({
    url: '/arbit/wcgroups_info/queryById/' + id,
    method: 'get'
  })
}

// 新增微信群信息
export function addWcGroupsInfo(data) {
  return request({
    url: '/arbit/wcgroups_info/add',
    method: 'post',
    data: data
  })
}

// 查询群好友统计
export function getGroupsFriend(data) {
  return request({
    url: '/arbit/wcgroups_user/data_groups_friendln',
    method: 'get',
    data: data
  })
}

// 查询新加群统计
export function getNewGroupNum(data) {
  return request({
    url: '/arbit/wcgroups_info/data_groups',
    data:data,
    method: 'get'
  })
}
// 群内发言
export function getGroupSpeak(data) {
    return request({
      url: '/arbit/wcgroups_info/dayGroupsSpeak',
      method: 'get',
      data: data
    })
}
</script>
<style scoped lang="scss">
  .app-container{
    background-color: #f6f9fb;
  }
  .frominfo{
    display: flex;background-color: #fff;padding: 10px;padding-bottom: 0; margin-bottom: 20px;
    .from-item{
      display: flex;flex-wrap: wrap;
    }
    .from-Btn{
      display: flex;flex-direction: column;align-items: center;justify-content: center;width: 20%;
    }
  }
  .blue-button {
    color: #fff;
    background-color: #0078fb;
    border-color: #0078fb;
  }
  .linebtn{
        display: flex;
        margin: -10px 0 10px 5px;
        height: 38px;
        .btn{
            width: 90px;
            text-align: center;
            line-height: 38px;
            font-size: 14px;
            color: #8c8c8c;
            margin-right: 10px;
            border: 1px solid #eaeff2;
            background-color: #fff;
            border-radius: 5px;
            .link-type{
              color: #8c8c8c;
            }
        }
        .select{
            background-color: #eaf6ff;
            border:1px solid #288dfc;
            color: #288dfc;
            font-weight: 550;
        }
  }
</style>